from django.db import models
import django.db.models.options as options

options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('isTwitterModel',)

# Create your models here.
'''Twitter models'''
class Tweet(models.Model):
    class Meta():
        isTwitterModel = True
        
    id = models.DecimalField(primary_key=True, max_digits=20, decimal_places=0)
    in_reply_to_status_id = models.DecimalField(max_digits=20, decimal_places=0)
    user = models.ForeignKey("User")
    text = models.TextField()
    created_at = models.DateTimeField()
    polarity = models.FloatField()
    polarity_ready = models.BooleanField()
    hashtags = models.TextField()
    
class User(models.Model):
    class Meta():
        isTwitterModel = True
        
    id = models.DecimalField(primary_key=True, max_digits=20, decimal_places=0)
    screen_name = models.TextField()
    statuses_count = models.DecimalField(max_digits=20, decimal_places=0)
    friends_count = models.DecimalField(max_digits=20, decimal_places=0)
    followers_count = models.DecimalField(max_digits=20, decimal_places=0)
    lang = models.TextField()
    followers_ready = models.BooleanField()
    user_ready = models.BooleanField()
    
class Friendship(models.Model):
    class Meta():
        isTwitterModel = True
        
    # user follows followed_user
    user = models.ForeignKey("User", related_name="twitter_user_follow_source")
    followed_user = models.ForeignKey("User", related_name="twitter_user_follow_destination")
    
    
'''Infrarouge models'''
class InfrarougeUser(models.Model):
    class Meta():
        db_table = "user"
    
    id = models.IntegerField(primary_key=True)
    name = models.TextField()
        
class InfrarougeForum(models.Model):
    class Meta():
        db_table = "forum"
        
    id = models.IntegerField(primary_key=True)
    title = models.TextField()
    description = models.TextField()
    
class InfrarougeForumThread(models.Model):
    class Meta():
        db_table = "forumthread"
        
    id = models.IntegerField(primary_key=True)
    title = models.TextField()
    description = models.TextField()
    url = models.TextField()
    fkparentforum = models.ForeignKey("InfrarougeForum")
    fkauthor = models.ForeignKey("InfrarougeUser")
    
class InfrarougeThreadMessage(models.Model):
    class Meta():
        db_table = "threadmessage"
        
    id = models.IntegerField(primary_key=True)
    message = models.TextField()
    fkforumthread = models.ForeignKey("InfrarougeForumThread")
    fkauthor = models.ForeignKey("InfrarougeUser")
    timestamp = models.DateTimeField()
    polarity = models.FloatField()
    
# does not work because Django doesn't support tables without primary keys or tables with composed primary key (more than 1 column)
class InfrarougeReply(models.Model):
    class Meta():
        db_table = "reply"
        
    id = models.IntegerField(primary_key=True)
    fkfrom = models.ForeignKey("InfrarougeUser", related_name="infrarougeuser_infrarougereply_from")
    fkto = models.ForeignKey("InfrarougeUser", related_name="infrarougeuser_infrarougereply_to")
    fkthreadmessage = models.ForeignKey("InfrarougeThreadMessage")